package cn.lanqiao.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class IOTest {

    public static void main(String[] args) {
        new IOTest().ByteIOByByte();
    }

    public void ByteIOByByte() {
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream("/Users/David/Desktop/a.txt");
            out = new FileOutputStream("/Users/David/Desktop/b.txt");
            byte[] bytes = new byte[10];
            int c;
            while ((c = in.read(bytes)) != -1) {
                System.out.println(c);
                out.write(bytes,0,c);
                out.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
